package com.compass.mobile.ui.dialog

import android.annotation.SuppressLint
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import androidx.fragment.app.FragmentActivity
import androidx.leanback.widget.ArrayObjectAdapter
import androidx.leanback.widget.BaseGridView
import androidx.leanback.widget.FocusHighlight
import androidx.leanback.widget.FocusHighlightHelper
import com.compass.mobile.callback.OnCustomButtonClick
import com.compass.mobile.callback.OnItemClickListener
import com.compass.mobile.databinding.DialogInspectSelectedBinding
import com.compass.mobile.databinding.DialogTickectBinding
import com.compass.mobile.framework.base.BaseDialog
import com.compass.mobile.framework.base.BaseDialogFragment
import com.compass.mobile.framework.ext.onClick
import com.compass.mobile.framework.utils.FocusViewUtils
import com.compass.mobile.framework.utils.dpToPx
import com.compass.mobile.models.IndependentBillingBean
import com.compass.mobile.models.TicketModel
import com.compass.mobile.presenters.NumberSegmentPresenter
import com.compass.mobile.widget.MyBridgeAdapter

/**
 * Description： 预约挂号弹窗
 * Date:2024/6/25 17:08
 */
class NumberSegmentDialog {
    class Builder(
        activity: FragmentActivity,
        private var ticlets: MutableList<TicketModel>,
        onItemClickListener: OnItemClickListener
    ) :
        BaseDialogFragment.Builder<Builder>(activity) {

        private var onItemClickListener: OnItemClickListener
        private val mBinding: DialogTickectBinding =
            DialogTickectBinding.inflate(LayoutInflater.from(activity))

        init {
            this.onItemClickListener = onItemClickListener
            initView()
        }

        private fun initView() {
            setContentView(mBinding.root)
            setWidth((AppManager.getScreenHeightPx() * 0.8).toInt())
            setHeight((AppManager.getScreenWidthPx() * 0.8).toInt())
            setAnimStyle(BaseDialog.AnimStyle.DEFAULT)
            setGravity(Gravity.CENTER)
            setCancelable(true)
            specialColumn()

        }
        fun dismissDialog(){
            dismiss()
        }

        @SuppressLint("RestrictedApi")
        fun specialColumn() {
            mBinding.caseItem.setNumColumns(3)
            mBinding.caseItem.horizontalSpacing = dpToPx(10)
            mBinding.caseItem.verticalSpacing = dpToPx(10)
            val arrayObjectAdapter = ArrayObjectAdapter(NumberSegmentPresenter())
            val itemBridgeAdapter = MyBridgeAdapter(
                activity,
                arrayObjectAdapter, onItemClickListener
            )
            mBinding.caseItem.setAdapter(itemBridgeAdapter)
            mBinding.caseItem.setFocusScrollStrategy(BaseGridView.FOCUS_SCROLL_ITEM)
            arrayObjectAdapter.addAll(0, ticlets)
            FocusHighlightHelper.setupBrowseItemFocusHighlight(
                itemBridgeAdapter,
                FocusHighlight.ZOOM_FACTOR_NONE, false
            )
            mBinding.caseItem.requestFocus()
        }

    }
}